package cn.selfiot.iotman.view.projectitem;

import cn.selfiot.iotman.core.I18N;
import cn.selfiot.iotman.model.mqtt.ProjectModel;
import cn.selfiot.iotman.view.ResourceConstants;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ResourceBundle;

/**
 * @author hugo
 * @since 2020/7/30
 */
public class ProjectItem extends AnchorPane {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProjectItem.class);
    
    public ProjectItem(Stage stage, ProjectModel project) {
        super();
        String fxml = ResourceConstants.PROJECT_ITEM_RES;
        try {
            ResourceBundle bundle = I18N.getBundle();
            FXMLLoader loader = new FXMLLoader(getClass().getResource(fxml), bundle);
            ProjectItemController controller = new ProjectItemController();
            controller.setMqttProject(project);
            controller.setPrimaryStage(stage);
            loader.setController(controller);
            
            Node node = loader.load();
            this.getChildren().add(node);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.error(e.getMessage());
        }
    }
}
